// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class ChatItem extends cc.Component {

    @property(cc.Sprite)
    icon: cc.Sprite = null;
    @property(cc.Label)
    chatTxt: cc.Label = null;
    @property(cc.Label)
    playerNameTxt: cc.Label = null;


    drawItem(obj: any) {
        this.chatTxt.string = obj.message;
        this.playerNameTxt.string = obj.nickName != null ? obj.nickName : "？？？";

        cc.resources.load("icons/" + obj.avatar, cc.SpriteFrame, (error: Error, spriteFrame: cc.SpriteFrame) => {
            this.icon.spriteFrame = spriteFrame;
        });
    }
}
